Support shebang lines with amended environment
authorKévin Le Gouguec <kevin.legouguec@gmail.com>
Sat, 10 Feb 2024 16:56:57 +0000 (17:56 +0100)
committerEli Zaretskii <eliz@gnu.org>
Sat, 17 Feb 2024 08:31:47 +0000 (10:31 +0200)
For bug#64939.

* lisp/files.el (auto-mode-interpreter-regexp): Account for possible
VARIABLE=[VALUE] operands.
* test/lisp/files-tests.el (files-tests-auto-mode-interpreter):
Add an example from the coreutils manual.

lisp/files.el
test/lisp/files-tests.el

index 5098d49048e148e36f5ad99612386e19837f7959..524385edc847ff06a6a7a0bde33e8203eec10129 100644 (file)
@@ -3274,12 +3274,15 @@ and `inhibit-local-variables-suffixes'.  If
     ;; Optional group 1: env(1) invocation.
     "\\("
     "[^ \t\n]*/bin/env[ \t]*"
-    ;; Within group 1: possible -S/--split-string.
+    ;; Within group 1: possible -S/--split-string and environment
+    ;; adjustments.
     "\\(?:"
     ;; -S/--split-string
     "\\(?:-[0a-z]*S[ \t]*\\|--split-string=\\)"
     ;; More env arguments.
     "\\(?:-[^ \t\n]+[ \t]+\\)*"
+    ;; Interpreter environment modifications.
+    "\\(?:[^ \t\n]+=[^ \t\n]*[ \t]+\\)*"
     "\\)?"
     "\\)?"
     ;; Group 2: interpreter.
index 0a5c3b897e488afbd5fa16a2fd9bb9f6ab67a06b..d4c1ef3ba674a99c849ee80861d2a31eeee647f6 100644 (file)
@@ -1694,7 +1694,9 @@ set to."
   (files-tests--check-shebang "#!/usr/bin/env -S-vi bash -eux" 'sh-base-mode 'bash)
   (files-tests--check-shebang "#!/usr/bin/env -ivS --default-signal=INT bash -eux" 'sh-base-mode 'bash)
   (files-tests--check-shebang "#!/usr/bin/env -ivS --default-signal bash -eux" 'sh-base-mode 'bash)
-  (files-tests--check-shebang "#!/usr/bin/env -vS -uFOOBAR bash -eux" 'sh-base-mode 'bash))
+  (files-tests--check-shebang "#!/usr/bin/env -vS -uFOOBAR bash -eux" 'sh-base-mode 'bash)
+  ;; Invocation through env, with modified environment.
+  (files-tests--check-shebang "#!/usr/bin/env -S PYTHONPATH=/...:${PYTHONPATH} python" 'python-base-mode))
 
 (ert-deftest files-test-dir-locals-auto-mode-alist ()
   "Test an `auto-mode-alist' entry in `.dir-locals.el'"